import java.util.Random;
import java.util.Scanner;

public class Test {

    /*
    在同一个类中定义多个方法：
    要求不仅可以求2个整数的最大值，
    还可以求3个小数的最大值？
     */

    public static double Max(double x, double y, double z){
        if(x > y && x > z){
            return x;
        }else if(y > x && y > z){
            return y;
        }else{
            return z;
        }
    }

    public static int Max(int x, int y){
        return x > y ? x : y;
    }

    public static void main(String[] args) {
        int ret1 = Max(10, 20);
        double ret2 = Max(3.14, 6.25, 4.26);
        System.out.println("ret1 = " + ret1);
        System.out.println("ret2 = " + ret2);
    }

    public static int facNSum(int x){
        int sum = 0;
        for(int i = 1; i <= x; i++){
            sum += facN(i);
        }
        return sum;
    }

    public static int facN(int x){
        int ret = 1;
        for(int i = 1; i <= x; i++){
            ret *= i;
        }
        return ret;
    }

    // 求1！+2！+3！+4！+........+n!的和
    public static void main10(String[] args) {
        int ret = facNSum(5);
        System.out.println(ret);
    }

    /*
    编写代码模拟三次密码输入的场景。 最多能输入三次密码，密码正确，
    提示“登录成功”,密码错误， 可以重新输入，最多输入三次。三次均错，则提示退出程序
    */
    public static void main9(String[] args) {

        int count = 3;
        boolean flag = false;
        Scanner in = new Scanner(System.in);
        int rightPassword = 123456;
        System.out.println("您最多能输入3次,请输入您的密码:");

        while(count != 0){
            int password = in.nextInt();
            if(rightPassword == password){
                System.out.println("密码正确,登录成功!");
                flag = true;
                break;
            }else{
                count--;
                System.out.println("密码错误, 剩下" + count + "次机会");
                if(count != 0){
                    System.out.println("请重新输入:");
                }
            }
        }
        if(flag == false){
            System.out.println("您的次数使用完,登录失败!");
        }
    }
    // 输出一个整数的每一位，如：123的每一位是3，2，1
    public static void main8(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个整数:");
        int num = in.nextInt();
        while(num != 0){
            System.out.print(num % 10);
            System.out.print(" ");
            num /= 10;
        }
    }

    public static Double add(double x, double y){
        return x + y;
    }

    public static int add(int x, int y){
        return x + y;
    }

    public static int add(int x, int y, int z){
        return x + y;
    }

    public static void main7(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        int ret = add(a, b, c);
        System.out.println(ret);

        double d1 = 3.14;
        double d2 = 6.8;
        double ret2 = add(d1, d2);
        System.out.println(ret2);
    }
    public static void main6(String[] args) {
        /*boolean flag = isLeapYear(2026);
        System.out.println(flag);*/

        /*int a = 10;
        int b = 20;
        int ret = add(a, b);
        System.out.println(ret);*/

        /*int ret = facSumDev(5);
        System.out.println(ret);*/

        int a = 10;
        int b = 20;
        System.out.println("交换前: a = " + a + ", b = " + b);
        swap(a, b);
        System.out.println("交换后: a = " + a + ", b = " + b);

    }

    public static void swap(int x, int y){
        int tmp = x;
        x = y;
        y = tmp;
    }

    /**
     * 求 1! + 2! + 3! + ... + n!
     */
    /*public static int facSumDev(int x){
        int sum = 0;
        for(int i = 1; i <= x; i++){
            sum += fac(i);
        }
        return sum;
    }*/

    /**
     * 求n的阶乘
     */
    /*public static int fac(int x){
        int ret = 1;
        for(int i = 1; i <= x; i++){
            ret *= i;
        }
        return ret;
    }*/



    public static boolean isLeapYear(int year) {
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            return true;
        }else{
            return  false;
        }
    }
    public static void main5(String[] args) {
        Random rand = new Random();
        int num = rand.nextInt(100)+1;
        Scanner in = new Scanner(System.in);
        while(true){
            System.out.println("请输入您要猜测的数字:");
            int guessNum = in.nextInt();
            if(guessNum > num){
                System.out.println("猜大了");
            }else if(guessNum < num){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }

        in.close();
    }

    public static void main4(String[] args) {
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            int num = random.nextInt(100); // [0, 100)
            // int num = random.nextInt(121)+30; [30,150]
            System.out.println(num);
        }
    }

    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){ // 多行输入
            String name = in.nextLine();
            System.out.println(name);
        }
    }

    public static void main2(String[] args) {
        //        =  对象 --->标准输入
        Scanner in = new Scanner(System.in);

        String name1 = in.next(); // 遇到空格就结束
        System.out.println(name1);

        System.out.println("请输入您的年龄:");
        int age = in.nextInt();
        in.nextLine();

        System.out.println("请输入您的姓名: ");
        String name = in.nextLine(); // 读取一行

        System.out.println("请输入您的薪资:");
        double money = in.nextDouble();

        System.out.println("姓名:"+ name +",年龄:"+ age + ",薪资:"+ money);

        in.close();
    }
    public static void main1(String[] args) {
        // 打印 1 - 100 之间所有的素数
        /*for(int i = 2; i <= 100; i++){
            int j = 0;
            for(j = 2; j <= Math.sqrt(i); j++){
                if(i % j == 0){
                    break;
                }
            }
            if(j > Math.sqrt(i)){
                System.out.println(i);
            }
        }*/

        // 输出 1000 - 2000 之间所有的闰年
        /*for(int year = 1000; year <= 2000; year++){
            if(year % 100 != 0){
                if(year % 4 == 0){
                    System.out.println(year);
                }
            }else{
                if(year % 400 == 0){
                    System.out.println(year);
                }
            }
        }*/

        // 编写程序数一下 1到 100 的所有整数中出现多少个数字9
        int count = 0;
        for(int i = 1; i <= 100; i++){
            if(i % 10 == 9){ // 判断个位数的9
                count++;
            }

            if(i / 10 == 9){ // 判断十位数的9
                count++;
            }
        }
        System.out.println(count);

        // 求出0～n之间的所有“水仙花数”并输出。
        // (“水仙花数”是指一个三位数，其各位数字的立方和确好等于该数本 身，如；153＝1^3＋5^3＋3^3，则153是一个“水仙花数“。）
        /*for(int i = 1; i < 999999; i++){
            // 求次方
            int count = 0;
            int tmp = i;
            while(tmp != 0){
                tmp /= 10;
                count++;
            }

            // 求 如；153＝1^3＋5^3＋3^3
            int sum = 0;
            tmp = i;
            while(tmp != 0){
                int num = tmp % 10;
                tmp /= 10;
                sum += Math.pow(num, count);
            }

            if(sum == i){
                System.out.println(sum);
            }
        }*/

        // 求2个整数的最大公约数 ---> 辗转相除法
        /*int a = 16;
        int b = 24;
        int c = a%b;
        while(c != 0){
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);*/

        // 计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        /*double sum = 0;
        int flag = 1;
        for(int i = 1; i <= 100; i++){
            sum += 1.0/i*flag;
            flag = -flag;
        }
        System.out.println(sum);*/

        /*for (int i = 0; i < 6; i++) {
            for(int j = 0; j < 6; j++){
                if(i == j || i + j == 5){
                    System.out.print("*");
                }else{
                    System.out.print(" ");
                }
            }
            System.out.println();
        }*/

        /*Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int num = in.nextInt();
            for(int i = 0; i < num; i++){
                for(int j = 0; j < num; j++){
                    if(i == j || i + j == num-1){
                        System.out.print("*");
                    }else{
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }*/
    }
}
